<?php

declare(strict_types=1);

namespace DreamCat\StateMachine\Popo;

use DreamCat\StateMachine\Enums\ActionStatusCodeEnum;

/**
 * 动作状态查询结果
 * @author vijay
 */
class ActionStatus
{
    /** @var ActionStatusCodeEnum 状态码 */
    private ActionStatusCodeEnum $statusCode;
    /** @var string 状态描述，比如未开始、进行中、暂停、完成、异常 */
    private string $statusText;
    /** @var SingleTask[] 任务列表 */
    private array $taskList = [];
    /** @var int 预期的结束时间 */
    private int $expectFinishTime;

    /**
     * @return ActionStatusCodeEnum 状态码
     */
    public function getStatusCode(): ActionStatusCodeEnum
    {
        return $this->statusCode ?? ActionStatusCodeEnum::EXCEPTION();
    }

    /**
     * @param ActionStatusCodeEnum $statusCode 状态码
     */
    public function setStatusCode(ActionStatusCodeEnum $statusCode): ActionStatus
    {
        $this->statusCode = $statusCode;
        return $this;
    }

    /**
     * @return string|null 状态描述
     */
    public function getStatusText(): ?string
    {
        return $this->statusText ?? null;
    }

    /**
     * @param string $statusText 状态描述
     */
    public function setStatusText(string $statusText): ActionStatus
    {
        $this->statusText = $statusText;
        return $this;
    }

    /**
     * @return SingleTask[] 任务列表
     */
    public function getTaskList(): array
    {
        return $this->taskList;
    }

    /**
     * @param SingleTask[] $taskList 任务列表
     */
    public function setTaskList(array $taskList): ActionStatus
    {
        $this->taskList = [];
        foreach ($taskList as $singleTask) {
            $this->addTask($singleTask);
        }
        return $this;
    }

    public function addTask(SingleTask $singleTask): ActionStatus
    {
        $this->taskList[] = $singleTask;
        return $this;
    }

    public function clearTasks(): ActionStatus
    {
        $this->taskList = [];
        return $this;
    }

    /**
     * @return ?int 预期的结束时间
     */
    public function getExpectFinishTime(): ?int
    {
        return $this->expectFinishTime ?? null;
    }

    /**
     * @param int $expectFinishTime 预期的结束时间
     */
    public function setExpectFinishTime(int $expectFinishTime): ActionStatus
    {
        $this->expectFinishTime = $expectFinishTime;
        return $this;
    }
}

# end of file
